class MyPage extends BaseEditMaster {
    constructor(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
            returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl) {
        super(dataId, currentTaskPrivileges, nextTaskPrivileges, pageStatus, pageListData,
                returnUrl, fetchDataUrl, saveUrl, exportUrl, printUrl);
        this.hasFilterValue = true;
    }
    GetFilterValue() {
        let item = {};
        item['HeaderId'] = this.dataId;

        return item;
    }
    // 得到数据
    GetEntityData() {
        let item = {};
        item['bulletinId'] = $.trim($("#BulletinId").val());
        item['title'] = $.trim($("#Title").val());
        item['contents'] = window.CKEDITOR.instances.Contents.getData();
        item['startTime'] = $.trim($("#StartTime").val());
        item['endTime'] = $.trim($("#EndTime").val());
        item['channel'] = $.trim($("#Channel").val());
        item['priority'] = $.trim($("#Priority").val());
        item['createdBy'] = $.trim(parent.$("#UserId").val());
        item['updatedBy'] = $.trim(parent.$("#UserId").val());

        return JSON.stringify(item);
    }
    FillData(data) {
        $("#BulletinId").val(data.bulletinId);
        $("#Title").val(data.title);
        $("#StartTime").val(data.startTime);
        $("#EndTime").val(data.endTime);
        $("#Channel").val(data.channel);
        $("#Priority").val(data.priority);
        window.CKEDITOR.instances.Contents.setData(data.contents);

        this.SetPageElementStatus(this.HidePageElement, this.ShowPageElement, function () { });
        $("#Title").focus();
    }
    Save() {
        super.Save(function (data, _this) {
            if (data > 0) {
                if (parseInt(_this.pageStatus) === 1) {
                    $("#HeaderId").val(data);   // 设置刚才插入的记录ID
                    $("#Action").val(2);
                    _this.dataId = data;
                    _this.pageStatus = 2;
                    $("#panelSlave").show();
                    $("#ButPrint").show();
                    $("#CheckedTip").removeClass().addClass("n2");
                    $("#CheckedTip").html("状态：未审核。");
                    $("#CheckedTip").show();
                }
            }
        });
    }
    New() {
        super.New();
        // 默认设置一些值
        $("#BulletinId").val();
        $("#StartTime").val(getCurrentDate());
        $("#EndTime").val(getCurrentDate());

        $("#Title").focus();
    }
    ShowPageElement() {
        $("#ButSave").show();
        $("#panel_slave_butbar_01").show();
    }
    HidePageElement() {
        $("#ButSave").hide();
        $("#panel_slave_butbar_01").hide();
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let _pageStatus = parseInt($("#Action").val());
    let _dataId = $("#BulletinId").val();
    this.dataId = _dataId;

    let bulletin_list_result = $.cookie("bulletin_list_result") === undefined ? "" : $.cookie("bulletin_list_result");
    let _pageListData = [];
    if (bulletin_list_result !== "") {
        _pageListData = bulletin_list_result.split(',');
        $("#rec_total_rows").text(_pageListData.length);
        $("#rec_cur_row").text($.inArray(_dataId, _pageListData) + 1);

        if (_pageListData.length > 0) {
            let index = $.inArray(_dataId, _pageListData);
            if (index === 0) {
                $("#ButPrev").attr("disabled", "disabled");
            } else {
                $("#ButNext").removeAttr("disabled");
            }
            if (index === (_pageListData.length - 1)) {
                $("#ButNext").attr("disabled", "disabled");
            } else {
                $("#ButPrev").removeAttr("disabled");
            }
        }
    } else {
        $("#rec_total_rows").text("1");
        $("#rec_cur_row").text("1");
    }

    _Instance = new MyPage(_dataId, 0, 0, _pageStatus, _pageListData,
            "/oa/bulletin/list.html",
            "/oa/bulletin/fetchByBulletinId.html",
            "/oa/bulletin/save.html",
            "", "");

    window.laydate.render({
        elem: '#StartTime',
        type: 'date',
        theme: '#393D49',
        trigger: 'click'
    });
    window.laydate.render({
        elem: '#EndTime',
        type: 'date',
        theme: '#393D49',
        trigger: 'click'
    });

    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    let h = $(window).height();
    //$("#cke_Contents").css({height: h - 300});
    $("#cke_1_contents").css({height: h - 370});
}

//-----------------------------------------------------------------------------
// 验证函数
//-----------------------------------------------------------------------------
$.validator.setDefaults({
    ignore: 'hidden, [reaonly=readonly]'
});
$(function () {
    $("#form_data").validate({
        // Step 1：设置验证规则和错误消息
        rules: {
            _Title: "required",
            _Channel: "required",
            _Priority: "required"

        },
        messages: {
            _Title: "请填写标题。",
            _Channel: "请填写级别。",
            _Priority: "请填写紧急级别。"
        },
        // Step 2：设置验证触发事件
        onclick: false,
        onfocusout: false,
        onfocusin: false,
        onkeyup: false,
        onkeydown: false,
        focusInvalid: false,
        // Step 3：设置错误信息提示
        showErrors: window.showErrors  //使用自定义的错误显示方法
    });
});